package com.zhuzi.utils;

import javax.jms.*;

/**
 * @author zhuzi
 * 2023/12/27 20:34
 */
public class SysUtils {

    public static String getString(Message message) throws JMSException {
        String str = "";
        if (message instanceof BytesMessage) {
            BytesMessage bytesMessage = (BytesMessage) message;
            Integer len = (int) bytesMessage.getBodyLength();
            byte[] byteArr = new byte[len];
            for (int i = 0; i < len; i++) {
                byteArr[i] = bytesMessage.readByte();
            }
            str = new String(byteArr);
        } else if (message instanceof ObjectMessage) {
            ObjectMessage objMessage = (ObjectMessage) message;
            str = objMessage.getObject().toString();
        } else if (message instanceof StreamMessage) {
            StreamMessage streamMessage = (StreamMessage) message;
            str = streamMessage.readString();
        } else if (message instanceof TextMessage) {
            TextMessage textMessage = (TextMessage) message;
            str = textMessage.getText();
        }
        return str;
    }
}
